<?php

require_once BaseUtil::getModulePath ( "dbgrid" ) . '/DBGrid.php';
require_once BaseUtil::getModulePath ( "dbgrid" ) . '/DBGridConstant.php';
require_once BaseUtil::getModulePath ( "base" ) . '/services/BaseService.php';
require_once BaseUtil::getModulePath ( "cms" ) . '/models/FeaturePageDao.php';

class FeaturePageService extends BaseService {
	
	private $featurepageDao;
	
	public function __construct() {
		parent::__construct();
		$this->featurepageDao=new FeaturepageDao();
		$this->featurepageDao->setDb($this->db);
	}
	
	public function getPages($view,$form) {
		$dbgrid=new DBGrid($view);
		$dbgrid->setPost($form);
		$dbgrid->setModule("/cms/featurepage");
		$dbgrid->addValueFilter("is_delete",0);
		$dbgrid->addFilter(DBGridConstant::FILTER_TYPE_TEXT,'url',$this->_translate->translate("url"));
		$dbgrid->addFetchTable("feature_pages","*");
		$dbgrid->addFetchColumn("url",$this->_translate->translate("url"),"edit");
		/*$dbgrid->addFetchColumn("css",$this->_translate->translate("css"));
		$dbgrid->addFetchColumn("javascript",$this->_translate->translate("javascript"));
		$dbgrid->addFetchColumn("html",$this->_translate->translate("html"));*/
		//module action
		$dbgrid->addAAModuleAction("featurepage","edit",$this->_translate->translate("editBtn"),"edit");
		$dbgrid->addAAModuleAction("featurepage","add",$this->_translate->translate("addBtn"),"add");
		$dbgrid->addAAModuleAction("featurepage","delete",$this->_translate->translate("delBtn"),"deletesome");
		$dbgrid->setPageTitle($this->_translate->translate("searchTitle"));
		return $dbgrid->render();
	}
	
	public function addPage($form) {
		$page=array();
		$page["url"]=$form->getValue("url");
		$page["css"]=$form->getValue("css");
		$page["javascript"]=$form->getValue("javascript");
		/*print_r($page["javascript"]);
		exit();*/
		$page["html"]=$form->getValue("html");
		$this->featurepageDao->insertData($page);
	}
	
	public function editPage($form) {
		$page=array();
		$page["url"]=$form->getValue("url");
		$page["css"]=$form->getValue("css");
		$page["javascript"]=$form->getValue("javascript");
		$page["html"]=$form->getValue("html");
		$this->featurepageDao->updatePage($page,$form->getValue("id"));
	}
	
	public function getPageById($id) {
		return $this->featurepageDao->getByCol("id",$id);	
	}
	
	public function deletePage($ids) {
	   foreach ($ids as $id) {
            if (!empty($id)) {
                $this->featurepageDao->deletePage($id);
            }
        }
	}
	
	public function delete($ids) {
	   if(!empty($ids)) {
            $this->featurepageDao->deletePage($ids);
       }
	}
}

